package com.wu.llpsw.tool;


import com.mojang.math.Vector3d;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;

import java.util.ArrayList;
import java.util.List;

/**
 * 查询的工具类
 */
public class select {
    //查询玩家是否是第一次加入游戏
    public static boolean isFirstJoin(Player player){
        //获取玩家数据包
        CompoundTag playerData = player.getPersistentData();
        // 第一次加入游戏的逻辑
        if (!playerData.contains("first")) {
            playerData.putBoolean("first", true);
            return true;
        }
        return false;
    }


    //查询指定位置周围的非玩家生物实体
    public static List<LivingEntity> getEntitiesAround(Level world, double x, double y, double z, double range) {
        AABB aabb = new AABB(
                x - range, y - range, z - range,
                x + range, y + range, z + range
        );

        // 获取指定范围内的所有生物实体
        List<LivingEntity> entities = world.getEntitiesOfClass(LivingEntity.class, aabb);
        List<LivingEntity> mid=new ArrayList<>();
        for(LivingEntity entity:entities){
            if(!(entity instanceof Player)){
                mid.add(entity);
            }
        }
        return  mid;
    }

    //查询周围的玩家
    public static List<Player> getAroundPlayer(Level world, double x, double y, double z, double range){
        AABB aabb = new AABB(
                x - range, y - range, z - range,
                x + range, y + range, z + range
        );
        // 获取指定范围内的所有生物实体
        List<Player> entities = world.getEntitiesOfClass(Player.class, aabb);
        return  entities;
    }



}
